package com.servlet;

import com.bean.*;
import com.dao.BhcaseDao;
import com.dao.UsecasetrueDao;
import com.dao.impl.BhcaseDaoImpl;
import com.dao.impl.BhcasetmDaoImpl;
import com.dao.impl.BhtopicDaoImpl;
import com.dao.impl.UsecasetrueDaoImpl;
import com.google.gson.Gson;
import com.util.Timeone;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/UsecasetrueServlet/*")
public class UsecasetrueServlet extends BaseServlet {
    Gson gson = new Gson();
    protected void Huoti(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out= resp.getWriter();
        List<Bhcasetm> list = null;
        try {
            list = new BhcasetmDaoImpl().queryBhcasetm("select * from bhcasetm where cUrl=?",req.getParameter("Url"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(list+"az");
        String obj = gson.toJson(list);
        out.print(obj);
        out.flush();
        out.close();

    }
    //tim
    protected void Usecaet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BhcaseDao bhcaseDao = new BhcaseDaoImpl();
        List<Bhcase> list=( List<Bhcase> )req.getAttribute("list");
        req.setAttribute("Tim", Timeone.uTim(list.get(0).getcEnd()));
        req.setAttribute("list",list);
        req.getRequestDispatcher("/WEB-INF/jsp/Usecasetrue_KS.jsp").forward(req,resp);
    }

    protected void tim(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");
        PrintWriter out= resp.getWriter();
        List<Bhtopic> list=null;
        try {
            System.out.println(req.getParameter("ti"));
           list= new  BhtopicDaoImpl().queryBhtopic("select * from bhtopic where topIcID=?",req.getParameter("ti"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        String a = gson.toJson(list);
        out.print(a);
        out.flush();
        out.close();
    }

    protected void suan(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sd= req.getParameter("daan").replace(",,","\\");
        String rul=req.getParameter("url");
        BhUser bhUser=(BhUser)req.getSession().getAttribute("BhSyUser");
        UsecasetrueDao usecasetrueDao=new UsecasetrueDaoImpl();
        System.out.println(bhUser.getuID());
        Usecasetrue usecasetrue=new Usecasetrue(rul,sd,bhUser.getuID());
        System.out.println("azaas");
        try {
            usecasetrueDao.dudas(usecasetrue);
            int i = new UsecasetrueDaoImpl().addUSum("select * from usecasetrue where uID="+bhUser.getuID()+" and cUrl='"+rul+"'");
            resp.sendRedirect("/BhSyCase/cheng/CheTao?url="+rul);
            System.out.println("%"+new UsecasetrueDaoImpl().getmap("select * from usecasetrue where uID="+bhUser.getuID()+" and cUrl='"+rul+"'")+"%");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
